/*
 * @Author: your name
 * @Date: 2021-04-13 19:48:23
 * @LastEditTime: 2021-05-15 16:22:06
 * @LastEditors: Please set LastEditors
 * @Description: 文献集锦
 * @FilePath: /medicine-web/src/store/modules/document.js
 */
import rest from './../rest'
const document = {
  state: {
    filterMap: {}, // 过滤字段
    resetSort: true, // 重置排序
  },
  mutations: {
    SET_BANNER_FLITER (state, data) {
      state.filterMap = data
    },
    RESET_SORT (state, data) {
      state.resetSort = !state.resetSort
    }
  },
  actions: {
    setFilter ({ commit }, data) {
      commit('SET_BANNER_FLITER', data)
    },
    resetSort ({ commit }, data) {
      commit('RESET_SORT', data)
    },
    async getDocumentDetail({ commit }, data) { // 获取文献详情
      const res = await rest.get('document/info', data)
      if (res && res.code === 200) {
        return res.data
      }
      return {}
    },
    async getDocumentList({ commit }, data) { // 获取文献列表
      const res = await rest.get('document/search', data)
      if (res && res.code === 200) {
        return res.data
      }
      return {}
    },
    async getDocumentStatitics({ commit }, data) {
      const res = await rest.get('document/report')
      if (res && res.code === 200) {
        return res.data
      }
      return {}
    },
    async getHotAndAuthor({ commit }, data) {
      const res = await rest.get('pub/index', {})
      if (res && res.code === 200) {
        return res.data
      }
      return {}
    }
  },
  getters: {
    filterMap: (state) => state.filterMap, // 条件
    resetSort: (state) => state.resetSort // 重置排序
  }
}
export default document
